package core.modules.developer.entity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import core.util.WebUtil;

public class Table {
	private String author;
	private String module;
	private String javaName;
	private String name;
	private String remarks;
	private List<Column> columns;
	private String dateFlag;

	public static final HashSet<String> ignoreColumns = new HashSet<>();
	static {
		ignoreColumns.add("id");
		ignoreColumns.add("delflag");
		ignoreColumns.add("addtime");
		ignoreColumns.add("edittime");
	}

	public Table() {
	}

	public Table(String name, String remarks) {
		//this.javaName = name.replaceAll("_", "");
		this.javaName = WebUtil.camelCase(name);
		this.name = name;
		this.setRemarks(remarks);
		this.columns = new ArrayList<Column>();
		dateFlag = "0";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Column> getColumns() {
		return columns;
	}

	public List<Column> getEntityColumns() {
		List<Column> list = new ArrayList<>();
		for (Column column : columns) {
			if (!ignoreColumns.contains(column.getName())) {
				list.add(column);
			}
		}
		return list;
	}

	public void setColumns(List<Column> columns) {
		this.columns = columns;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public String getJavaName() {
		return javaName;
	}

	public String getJavaNameCapFirst() {
		char[] cs = javaName.toCharArray();
		cs[0] = Character.toUpperCase(cs[0]);
		return String.valueOf(cs);
	}
	public String getJavaNameUnCapFirst() {
		char[] cs = javaName.toCharArray();
		cs[0] = Character.toLowerCase(cs[0]);
		return String.valueOf(cs);
	}

	public void setJavaName(String javaName) {
		this.javaName = javaName;
	}

	public String getDateFlag() {
		return dateFlag;
	}

	public void setDateFlag(String dateFlag) {
		this.dateFlag = dateFlag;
	}

	public String getModule() {
		return module; 
	}

	public void setModule(String module) {
		this.module = module;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}
}